package com.clms.marketings.service.Impl;

import com.alibaba.nacos.common.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.clms.common.R;
import com.clms.marketings.mapper.TbCustomerIssuesMapper;
import com.clms.marketings.pojo.entity.TbCustomerIssues;
import com.clms.marketings.pojo.vo.CustomerIssuesVo;
import com.clms.marketings.service.TbCustomerIssuesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: clms-third
 * @description: 客服问答的业务逻辑层
 * @author: 赵露露
 * @create: 2021-07-23 10:05
 **/
@Service
public class TbCustomerIssuesServiceImpl implements TbCustomerIssuesService {
    @Autowired
    TbCustomerIssuesMapper tbCustomerIssuesMapper;
    @Override
    public R selectAll() {
        List<TbCustomerIssues> tbCustomerIssues=tbCustomerIssuesMapper.selectList(null);
        return R.ok().put("allcustomer",tbCustomerIssues);
    }
    @Override
    public R insertCustomerIssues(TbCustomerIssues tbCustomerIssues) {
        int insertCustomerIssues= tbCustomerIssuesMapper.insert(tbCustomerIssues);
        return R.ok();
    }

    @Override
    public R updateCustomerIssues(TbCustomerIssues tbCustomerIssues) {
        int updateCustomerIssues=tbCustomerIssuesMapper.updateById(tbCustomerIssues);
        return R.ok();
    }

    @Override
    public R deleteCustomerIssues(Integer id) {
        int deleteCustomerIssues= tbCustomerIssuesMapper.deleteById(id);
        return R.ok();
    }

    @Override
    public R selectById(Integer id) {
        TbCustomerIssues tbCustomerIssues=tbCustomerIssuesMapper.selectById(id);
        return R.ok().put("previews",tbCustomerIssues);
    }

    @Override
    public R selectPage(Integer currentPage, Integer pageSize, CustomerIssuesVo customerIssuesVo) {
        Page<TbCustomerIssues> page=new Page<>(currentPage,pageSize);
        QueryWrapper<TbCustomerIssues> queryWrapper=new QueryWrapper<>();
        if(StringUtils.isNotEmpty(customerIssuesVo.getSubmodule())){
            queryWrapper.like("submodule",customerIssuesVo.getSubmodule());
        }
        Page<TbCustomerIssues> page1= tbCustomerIssuesMapper.selectPage(page,queryWrapper);
        return R.ok().put("total",page1.getTotal()).put("records",page1.getRecords());
    }
}
